{template 'common/header'}

<ul class="nav nav-tabs">

	<li {if $op == 'post'} class="active" {/if}><a href="{php echo $this->createWebUrl('index',array('op' =>'post'))}">新建活动</a></li>

    <li {if $op == 'list'} class="active" {/if}><a href="{php echo $this->createWebUrl('index',array('op' =>'list'))}">活动列表</a></li>

    {if $op == 'player' || $op == 'award'}<li {if $op == 'player'}class="active"{/if} ><a {if $op == 'award'}href='{php echo $this->createWebUrl("index",array("op"=>"player","rid"=>$id))}'{/if}>参与者信息</a></li>{/if}
    {if $op == 'award'}<li class="active" ><a>中奖者信息</a></li>{/if}

</ul>

<style>

th{

	text-align: center !important;

}



td{

	text-align: center !important;

	white-space: normal !important;

	word-break: break-all !important;

}

</style>
{if $op == 'post'} 
{php load()->func('tpl');}
<form action="" method="post" class="form form-horizontal">
<input type="hidden" name="rid" value="{$item['id']}">
<div class="panel panel-default">
<div class="panel-heading">活动设置</div>
<div class="panel-body">
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">活动标题</label>
	<div class="col-sm-9 col-xs-12">
		<input class="form-control" name="title" value="{$item['title']}">
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">活动时间</label>
	<div class="col-sm-9 col-xs-12">
		{php echo tpl_form_field_daterange('date', array('start'=>date('Y-m-d H:i',$item['starttime']?$item['starttime']:time()),'end'=>date('Y-m-d H:i',$item['endtime']?$item['endtime']:time()+3600*24*7)), true)}
	</div>
</div>
 <div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">活动图片</label>
	<div class="col-sm-9 col-xs-12">
		{php echo tpl_form_field_multi_image('pictrues', unserialize($item['pictrues']))}
		<div class="help-block">建议图片尺寸：640*1080</div>
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">背景音乐</label>
	<div class="col-sm-9 col-xs-12">
		{php echo tpl_form_field_audio('video', $item['video'])}
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">红包金额</label>
	<div class="col-sm-9 col-xs-12">
		<div class="input-group">
		<input class="form-control" min="1" type="number" name="rednum" value="{$item['rednum']}">
		<div class="input-group-addon">至</div>
		<input class="form-control" min="0" type="number" name="rednum2" value="{$item['rednum2']}">
		<div class="input-group-addon">分</div>
		</div>
		<div class="help-block">红包金额区间，最大值0时，直接取最小值</div>
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享标题</label>
	<div class="col-sm-9 col-xs-12">
		<input class="form-control" name="stitle" value="{$item['stitle']}">
		<div class="help-block">注意：#排名#为当前粉丝排名</div>
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享图片</label>
	<div class="col-sm-9 col-xs-12">
		{php echo tpl_form_field_image('sthumb',$item['sthumb']);}
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享描述</label>
	<div class="col-sm-9 col-xs-12">
		<input class="form-control" name="sdesc" value="{$item['sdesc']}">
		<div class="help-block">注意：#排名#为当前粉丝排名</div>
	</div>
</div>
<div class="form-group">
	<label class="col-xs-12 col-sm-3 col-md-2 control-label">分享地址</label>
	<div class="col-sm-9 col-xs-12">
		<input class="form-control" name="surl" value="{$item['surl']}">
		<div class="help-block">不填默认为活动地址</div>
	</div>
</div>
</div>
</div>
<div class="panel panel-default">
	<div class="panel-heading">
		奖品信息
	</div>
	<input type="hidden" name="reply_id" value="{$reply['id']}" />
	<div class="panel-body">
		<div class="prizeitem" style="display:none;">
			<div><div class="form-group">
				<label class="col-xs-12 col-sm-3 col-md-2 control-label">中奖排名</label>
				<div class="col-sm-9">
					<input type="text" placeholder="请输入中奖排名数字，可输入多个排名数字，中间用英文逗号分隔，例如：9,99,999,9999" class="form-control" name="prizerank[]">
				</div>
			</div>
			<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">奖品图片</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_image('prizethumb[]','');}
					</div>
				</div>
			<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
					<div class="col-sm-9">
						<a class="btn btn-danger" onclick="onDel(this)">
							删除
						</a>
					</div>
				</div>
				<hr/></div>
		</div>
			{loop $awards $a}
				<div><div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">中奖排名</label>
					<div class="col-sm-9">
						<input type="text" placeholder="请输入中奖排名数字，可输入多个排名数字，中间用英文逗号分隔，例如：9,99,999,9999" class="form-control" name="prizerank[]" value="{$a['prizerank']}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">奖品图片</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_image('prizethumb[]',$a['prizethumb']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
					<div class="col-sm-9">
						<a class="btn btn-danger" onclick="onDel(this)" >
							删除
						</a>
					</div>
				</div>
				<hr/>
				</div>
			{/loop}
		<span id="award_insert_flag" style="display: none"></span>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">
			</label>
			<div class="col-sm-9">
				<button id="btn_add_award" type="button" class="btn btn-warning">
					<span class="glyphicon glyphicon-plus"></span> 添加奖品
				</button>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
			<div class="col-sm-9 col-xs-12">
				<button type="submit" name="submit" value="提交" class="btn btn-primary">提交</button>
				<input type="hidden" name="token" value="{$_W['token']}">
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$('#btn_add_award').bind('click', function(){
		$('#award_insert_flag').before($('.prizeitem').html());
	});
	
	function onDel(obj){
		var obj = $(obj).parent().parent().parent();
		obj.slideUp(300, function() {
			obj.remove();
		});
	}
</script>
</form>
{elseif $op == 'list'}

<div class="main" style="background: white;">

    <div style="padding:15px;">

        <table class="table table-hover">

            <thead class="navbar-inner">

                <tr>

                    <th>活动名称</th>

                    <th>活动时间</th>
                    
                    <th>活动链接</th>
                    
                    <th>红包链接</th>

                    <th style="width: 130px;">操作</th>

                </tr>

            </thead>

            <tbody>

                {loop $list $l}

                <tr>


                    <td><a href="{php echo $this->createWebUrl('index',array('op'=>'post','rid'=>$l['id']))}">{$l['title']}</a></td>

                    <td>开始时间：{php echo date('Y-m-d H:i:s',$l['starttime'])}<br>结束时间：{php echo date('Y-m-d H:i:s',$l['endtime'])}</td>

					<td>{php echo $_W['siteroot']."app/".$this->createMobileUrl('index',array('rid'=>$l['id']))}</td>
					
					<td>{php echo $_W['siteroot']."app/".$this->createMobileUrl('red',array('rid'=>$l['id']))}</td>

                    <td>

                    	<a href='{php echo $this->createWebUrl("index",array("op"=>"player","rid"=>$l["id"]))}' class="btn btn-warning btn-sm">参与会员({$l['attend']})</a>
                    	
                    	<a href='{php echo $this->createWebUrl("index",array("op"=>"award","rid"=>$l["id"]))}' class="btn btn-info btn-sm">中奖者({$l['award']})</a>

                    </td>

                </tr>

                {/loop}

            </tbody>

        </table>

    </div>

</div>

{elseif $op == 'player' || $op == 'award'}
<div class="panel panel-info">
        <div class="panel-heading">筛选</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal">
            <input type="hidden" name="rid" value="{$id}">
                <div class="form-group">
                   <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 200px;">姓名或者手机号码</label>
                    <div class="col-sm-2 col-lg-3">
	                    <input type="text" name="keyword" value="{$keyword}" class="form-control" style="display: inline-block;">
                    </div>
                   <button class="btn btn-default">搜索</button>
                   {if $op == 'player'}<a style="margin-left: 50px;" href='{php echo $this->createWebUrl("index",array("op"=>"award","rid"=>$id))}' class="btn btn-info">中奖记录</a>{/if}
                   <a style="margin-left: 50px;" href='{php echo $this->createWebUrl("export",array("rid"=>$id))}' class="btn btn-info">导出记录</a>
                </div>
            </form>
        </div>
</div>
<div class="main">
    <div style="padding:15px;background: white;">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr>
					<th style="width: 80px;">排名</th>
                    <th>粉丝</th>
                    <th>OPENID</th>
                    <th>真实姓名</th>
                    <th>手机号码</th>
                    <th>状态</th>
                    <th>参与时间</th>
                    <th style="width: 130px;">操作</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $k $l}
                <tr>
					<td>{php echo $k+1+($pindex-1)*$psize}</td>
                    <td><img src="{$l['avatar']}" style="width: 50px;height: 50px;"><br>{if $l['realname']}{$l['realname']}{else}{$l['nickname']}{/if}</td>
					<td>{$l['openid']}</td>
					<td>{$l['realname']}</td>
					<td>{$l['mobile']}</td>
                    <td>
	                    {if $l['dstatus'] == -1}<label class="label label-default" style="background: black;">已拉黑</label>
	                    {elseif !$l['mobile']}<label class="label label-default">未报名</label>
	                    {elseif $l['status']==1}<label class="label label-success">已领奖</label><br>({php echo unserialize($l['prize'])['prizename']})
	                    {elseif !$l['status'] && $l['prize']}<label class="label label-danger">已中奖</label>{/if}
	                    {if $l['rstatus']==1}<br><label class="label label-warning">红包已领</label>{/if}
                   	</td>
                    <td>{php echo date('Y-m-d H:i:s',$l['createtime'])}</td>
                    <td>

					{if empty($l['dstatus'])}
                    <a onclick="return confirm('确定拉黑吗？')" href='{php echo $this->createWebUrl("index",array("op"=>"dstatus","pid"=>$l["id"],"rid"=>$id))}' class="btn btn-danger btn-sm">拉黑</a>
                    {else}
                    <a onclick="return confirm('确定恢复吗？')" href='{php echo $this->createWebUrl("index",array("op"=>"dstatus1","pid"=>$l["id"],"rid"=>$id))}' class="btn btn-info btn-sm">恢复</a>
                    {/if}
                    {if empty($l['status']) && $l['prize']}
                    <a onclick="return confirm('确定发奖吗？')" href='{php echo $this->createWebUrl("index",array("op"=>"status","pid"=>$l["id"],"rid"=>$id))}' class="btn btn-success btn-sm">发奖</a>
                    {/if}
                    </td>
                </tr>
                {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
</div>
{/if}

{template 'common/footer'}